package com.android.controller;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class Connect_Webservice {
	
	public static SoapObject getConnectionFromWebservice(String METHOD_NAME, String NAMESPACE, String SOAP_ACTION, String URL){
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelop.setOutputSoapObject(request);
		HttpTransportSE androidHttp = new HttpTransportSE(URL);
		try {
			androidHttp.call(SOAP_ACTION, envelop);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		SoapObject soap = (SoapObject) envelop.bodyIn;
		return soap;
		
	}
	
	public static SoapObject getConnectionFromWebserviceWithPara(String METHOD_NAME, String NAMESPACE, String SOAP_ACTION, String URL, String name){
		
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//		SoapObject para = new SoapObject(NAMESPACE, METHOD_NAME); 
//		para.addProperty("cust_name", name);
//		request.addProperty(METHOD_NAME, para);
		
//		PropertyInfo pi = new PropertyInfo();
//		pi.setName("cust_name");
//		pi.setValue(name);
//		pi.setType(String.class);
//		
//		request.addProperty(pi);
		request.addProperty("cust_name",name);
				SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelop.setOutputSoapObject(request);
		HttpTransportSE androidHttp = new HttpTransportSE(URL);
		try {
			androidHttp.call(SOAP_ACTION, envelop);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		SoapObject soap = null;
		try {
			soap = (SoapObject) envelop.getResponse();
		} catch (SoapFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return soap;
		
	}
}
